/*
 * Bricks-OS, Operating System for Game Consoles
 * Copyright (C) 2008-2010 Maximus32 <Maximus32@bricks-os.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307 USA
 */


#ifndef ASM_CPU_H
#define ASM_CPU_H


#ifdef __cplusplus
extern "C"
{
#endif


// -----------------------------------------------------------------------------
static inline unsigned long
local_save_flags(void)
{
  unsigned long flags;
  __asm__ __volatile__("pushfl ; popl %0" : "=g" (flags) :);
  return flags;
}

// -----------------------------------------------------------------------------
static inline void
local_irq_restore(unsigned long flags)
{
  __asm__ __volatile__("pushl %0 ; popfl" :: "g" (flags) :"memory", "cc");
}

// -----------------------------------------------------------------------------
static inline void
local_irq_disable(void)
{
  __asm__ __volatile__("cli" ::: "memory");
}

// -----------------------------------------------------------------------------
static inline void
local_irq_enable(void)
{
  __asm__ __volatile__("sti" ::: "memory");
}

// -----------------------------------------------------------------------------
static inline void
halt(void)
{
  __asm__ __volatile__("hlt"::: "memory");
}


#ifdef __cplusplus
}
#endif


#endif
